package art.client.views;

import java.util.ArrayList;
import java.util.List;

import art.client.ClientFactory;
import art.client.widgets.ArtTable;
import art.client.widgets.ArtTableFilter;
import art.shared.entities.ArtShared;
import art.shared.entities.GenreShared;
import art.shared.entities.LoginInfo;
import art.shared.entities.UserLevelShared;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ArtsListView extends Composite implements IsWidget {

	VerticalPanel panel = new VerticalPanel();
	ArtTable table = null;
	ArtTableFilter filter = null;

	public ArtsListView(final ClientFactory factory, LoginInfo loginInfo, List<GenreShared> genres) {
		panel.add(factory.getMenuView(loginInfo));
		boolean allowDelete = false;
		if (loginInfo == null) {
			allowDelete = false;
		} else if (loginInfo.getUserLevel().equals(UserLevelShared.ADMIN)) {
			allowDelete = true;
		}
		table = new ArtTable(new ArrayList<ArtShared>(), loginInfo, allowDelete, genres);
		filter = new ArtTableFilter(table, genres);
		panel.add(filter);
		panel.add(table);
		initWidget(panel);
	}

	public void updateTable(List<ArtShared> arts) {
		table.updateData(arts);
	}
}
